package com.geek.gkbgw.web.demo;

import com.geek.gkbgw.facade.abs.Response;
import com.geek.gkbgw.web.model.BaseResponse;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("demo")
public class DemoController {

    @Setter
    @Getter
    @ToString
    public static class Info implements Serializable {
        @NotBlank
        String name;
        @NotBlank
        String age;
    }

    @GetMapping("/hello/{id}")
    public Response hello(@PathVariable String id){
        String msg = "DemoController recv args: id=" + id + ", date="
                +new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(new Date());
        return BaseResponse.ok(msg);
    }

    @GetMapping("/hello2/{id}")
    public Response hello2(@PathVariable String id){
        String msg = "DemoController recv args: id=" + Integer.parseInt(id)/0 + ", date="
                +new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(new Date());
        return BaseResponse.ok(msg);
    }

    @PostMapping("/hello3")
    public Response hello3(@RequestBody Info info){
        String msg = "DemoController recv args: id=" + info.toString() + ", date="
                +new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").format(new Date());
        return BaseResponse.ok(msg);
    }
}